package com.spl.mcm;

import java.util.ArrayList;

import com.spl.mcm.models.HistoryItem;
import com.spl.mcm.views.CustomListView;
import com.spl.mcm.views.ListItem;
import com.spl.mcm.views.ListItemAdapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageButton;

public class SMSFragment extends Fragment {
	/**
	 * The fragment argument representing the section number for this
	 * fragment.
	 */
	public static final String ARG_SECTION_NUMBER = "section_number";

	ListItemAdapter adapter;
	CustomListView listView;
	ImageButton btnEditList;
	Boolean isEditting = false;
	Button btnIntercepts;
	Button btnAddIntercept;
	Button btnClearHistory;
	
	public SMSFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.sms_page,
				container, false);
		
		ArrayList<ListItem> historyList = new ArrayList<ListItem>();
		HistoryItem item1 = new HistoryItem();
		item1.setContent("I love u");
		item1.setName("79");
		item1.setNumber("79");
		Time today = new Time(Time.getCurrentTimezone());
		today.setToNow();
		item1.setTime(today);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		historyList.add(item1);
		
		adapter = new ListItemAdapter(this.getActivity(), historyList);
		
		listView = (CustomListView)rootView.findViewById(R.id.list);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Log.i("SUMPRO", "onItemClick " + arg3);
			}
		});
		//get edit history button
		btnEditList = (ImageButton)rootView.findViewById(R.id.btnEditList);
		btnEditList.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				//clear all check if close editting mode
				if(isEditting == true)
					adapter.setCheckForAll(false);
				isEditting = !isEditting;
				listView.activeSelectItems(isEditting);
				adapter.setIsEditting(isEditting);
				
			}
		});
		
		//get intercept manager button
		btnIntercepts = (Button)rootView.findViewById(R.id.managerintercepts);
		btnIntercepts.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		btnAddIntercept = (Button)rootView.findViewById(R.id.addintercept);
		btnAddIntercept.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		btnClearHistory = (Button)rootView.findViewById(R.id.clearlist);
		btnClearHistory.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		return rootView;
	}
}
